package com.collins.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class CompletableTest {
    public static void main(String[] args) {
        ExecutorService tp = Executors.newFixedThreadPool(3);
        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.MILLISECONDS.sleep(1000);
                return Thread.currentThread().getName() + " hello";
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },tp).whenComplete((s, t) -> {
            System.out.println("end");
        }).exceptionally(e -> {
            e.printStackTrace();
            return "error";
        });

    }
}
